<!--ID:goods-car-->
<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../../libs/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" type="text/css" href="../../libs/app.css" />
		<link href="../../css/main.css" rel="stylesheet" />
		<link href="../../css/buy-car.css" rel="stylesheet" />
	</head>

	<body>
		<div class="head">
			<img class="mui-action-back" src="../../images/all-left.png" alt="">
			<p>我的购物车</p>
		</div>
		<div class="content mui-scroll-wrapper">
			<div class="mui-scroll">
				<!-- <div class="content-d">
    <div class="name"><p class="tit">名校贷学生贷</p><p><span>删除</span></p></div>
    <div class="picture">
        <div><span class="gou"></span></div>
        <div><div class="picture-d"><img src="../../images/school.png" width="100%" alt=""></div></div>
    </div>
    <p class="price">
        <span>价格¥：<span>10元</span></span>
        <span>会员价¥：<span>0元</span></span>
        <span>×<span>1</span></span>
    </p>
</div>
-->
				<!--<div class="content-d">
        <div class="name"><p class="tit">名校贷学生贷</p><p><span>删除</span></p></div>
        <div class="picture">
            &lt;!&ndash;<div><span class="gou"></span></div>&ndash;&gt;
            <div><div class="picture-d"><img src="../../images/school.png" width="100%" alt=""></div></div>
        </div>
        <p class="price">
            <span>价格¥：<span>10元</span></span>
            <span>会员价¥：<span>0元</span></span>
            <span>×<span>1</span></span>
        </p>
    </div>-->
			</div>
		</div>
		<div class="addmore">
			<button class="saddmore" onclick="getcar()">点击加载更多</button>
		</div>
		<div class="accound">
			<div class="bfc"></div>
			<div class="all-pay">
				<p>合计：¥<span class="allprice">0</span>元</p>
			</div>
			<div class="account">结算（<span class="all-times">0</span>）</div>
		</div>

		<script src="../../libs/mui.min.js"></script>
		<script src="../../js/jquery-3.1.1.min.js"></script>
		<script src="../../js/url.js"></script>
		<script src="../../js/userInfo.js"></script>
		<script type="text/javascript">
			var ERROR_OK = 'S002';
			var p = 0;
			var vip;

			var saveUsers = new User();
			saveUsers.def_hasVip()
				.then(function(data) {
					vip = data;
					getcar(data); // 查看购物车
				});

			//    console.log('vip='+ hasVip());
			/*查看购物车*/

			//    getcar();
			function getcar(vip) {
				p++;
				$.ajax({
						url: ur + 'rest/productController/list-order?page=' + p,
						type: 'GET',
						headers: {
							"X-Token": localStorage.token
						},
						dataType: 'json',
					})
					.done(function(data) {
						if(data.meta.code === ERROR_OK) {
							$('.all-times').text(data.data.total);
							localStorage.carNumber = data.data.total;
							if(data.data.total < 10) {
								$('.addmore').hide(0);
							} else if(data.data.total > 10) {
								$('.addmore').show(0);
							}
							var n = data.data.list.length;
							if(n > 0) {
								var allprice = 0;
								for(var i = 0; i < n; i++) {
									var div = $(
										'<div class="content-d">' +
										'<div class="name">' +
										'<p class="tit">' + data.data.list[i].productName + '</p>' +
										'<p><span class="det" id=' + data.data.list[i].id + '>删除</span></p>' +
										'</div>' +
										'<div class="picture"><div>' +
										//                                    '<span class="gou" id=' + data.data.list[i].price + '></span>' +
										'</div>' +
										'<div><div class="picture-d"><img src=' + ur + data.data.list[i].productImg + ' width="100%" alt=""></div>' +
										'</div></div>' +
										'<p class="price"> <span>价格¥：<span class="price1">' + data.data.list[i].price + '</span>元</span> <span>会员价¥：<span>' + data.data.list[i].vipPrice + '</span></span> ' +
										'<span>×<span>' + data.data.list[i].size + '</span></span></p>' +
										'</div>'
									);
									$('.content>.mui-scroll').append(div);
									if(vip) {
										allprice = allprice + data.data.list[i].vipPrice * data.data.list[i].size;
									} else {
										allprice = allprice + data.data.list[i].price * data.data.list[i].size;
									}
								}
								$('.allprice').text(allprice);
							} else if(n == 0) {
								mui.toast('没有更多');
							}
						} else {
							mui.toast(data.meta.message);
						}

					})
			}
			$(function () {
				/*从购物车删除*/
				$(".content").on('tap', '.det', function() {
					var cli = $(this).attr('id');
					var all = $(this).parents('.content-d');
					var price = vip ? all.find('.price').children().eq(1).children().text() : all.find('.price').children().eq(0).children().text();
					var n = all.find('.price').children().eq(2).children().text();
					var btnArray = ['否', '是'];
					mui.confirm('确认删除，确认？', '小马时贷', btnArray, function(e) {
						if(e.index == 1) {
							$.ajax({
									url: ur + 'rest/productController/update-shop',
									type: 'POST',
									dataType: 'json',
									headers: {
										"X-Token": localStorage.token
									},
									data: {
										"id": cli,
										"size": '0',
									}
								})
								.done(function(data) {
									if(data.meta.code == ERROR_OK) {
										all.fadeOut(500);
										mui.toast('删除成功');
										localStorage.carNumber = parseInt($('.all-times').text()) - 1;
										$('.all-times').text(parseInt($('.all-times').text()) - 1);
										$('.allprice').text($('.allprice').text() - price * n);
									} else {
										/*plus.nativeUI.closeWaiting();*/
									}
								})
						} else {}
					})
				});
				window.addEventListener('Clear', function() {
					$('.content>.mui-scroll').empty();
					$('.allprice').text(0);
					$('.all-times').text(0);
				});

			})

			mui('.mui-scroll-wrapper').scroll({ deceleration: 0.0010 });

			/*点击更新价格*/
			//    addall()

			function addall() {
				var v = $(".content>.mui-scroll>div").length;
				var b = 0;
				if(vip) {
					for(var a = 0; a < v; a++) {
						var i = $('.content>.mui-scroll>div').eq(a).children('.price').children().eq(1).children().text(); // 会员单价
						var n = $('.content>.mui-scroll>div').eq(a).children('.price').children().eq(2).children().text(); // 数量
						var c = b + i * parseInt(n);
					}
				} else {
					for(var a = 0; a < v; a++) {
						var i = $('.content>.mui-scroll>div').eq(a).children('.price').children().eq(0).children().text(); // 普通单价
						var n = $('.content>.mui-scroll>div').eq(a).children('.price').children().eq(2).children().text(); // 数量
						var c = b + i * parseInt(n);
					}
				}

				$('.allprice').text(c);
			}

			/*点击结算页面跳转*/
			account()

			function account() {
				$('.account').on('tap', function() {
					if($('.all-times').text() <= 0) {
						mui.toast('购物车内没有商品，不能结算');
					} else if($('.all-times').text() > 0) {
//						href('account.html', 'accound', { vip: vip });
						href('account.html');
					}
				})
			}
		</script>
	</body>

</html>